#include <stdio.h>
#include <stdlib.h>
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"

//This Unit Test Will Test the numHandCards() Function.
#define MAX_CARD treasure_map

//initialize game struct to array of 0's
void clearGameState(struct gameState *G) {
  int i;
	for (i=0; i<sizeof(struct gameState); i++) {
		((char *)G)[i] = 0;
	}
}

int main() {	

	int i, j;
	int currentPlayer, handCount;	//relevant to scoreFor() in dominion.c
	int card;
	int seed = 1003;			//FEEL FREE TO CHANGE
	int num_tests = 100;		//FEEL FREE TO CHANGE
	int errors = 0;
	int testVal, returnVal;
	struct gameState G;
	
	//initialize random number using rngs.c library
	SelectStream(1);
	PutSeed((long)seed);
	
	printf("Now Testing unittest 3: numHandCards() Function:\n");
	
	for (i=0; i < num_tests; i++) {
	  
	  clearGameState(&G);						//blank the game state
	 
	  currentPlayer = (int)(Random()*2)+2;		//get a random player number
	  
	  G.whoseTurn = currentPlayer; 			//Set the gameState to be that player's turn

	  handCount = (int)(Random()*(MAX_DECK/4));		//This will test values that are at least up to 125, which is plenty		
	  
	  //Create a hand for this player of random cards
	  for (j=0; j < handCount; j++) {
	     card = (int)(Random()*MAX_CARD);		
	     G.hand[currentPlayer][j] = card;		//place card in hand
	  }
	  
	  //assign handCount to this player in game state, also as temp variable.
	  G.handCount[currentPlayer] = testVal = handCount;
	  
	  //call function on gameState
	  returnVal = numHandCards(&G);
	  
	  //make sure returnVal and testVal match
	  if (returnVal != testVal) {
		printf("Error: Expected handCount to be %d, instead numHandCards() returned %d\n", testVal, returnVal);
		errors++;
	  }
	} // end main loop
	
	printf("Out of %d tests, %d returned error\n\n", num_tests, errors);

	return 0;
}